<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>选项卡</title>
        <style>
            *{
                margin: 0px;
                padding: 0px;
                list-style: none;

            }
            ul{
                overflow: hidden;
                margin-left: 600px;
            }
            ul li{
                float: left;
                width: 100px;
                height: 30px;
                margin-right: 10px;
            }
            ul li:nth-of-type(1){
                background: limegreen;
            }
            section>div{
                width: 500px;
                height: 200px;
                text-align: center;
                line-height: 200px;
                display: none;
                margin-left: 600px;
            }
            section>div:nth-of-type(1){
                display: block;
                background: orange;
            }
            section>div:nth-of-type(2){
               
                background: limegreen;
            }
            section>div:nth-of-type(3){
              
                background: sandybrown;
            }
            section>div:nth-of-type(4){
                
                background: yellow;
            }
            section>div:nth-of-type(5){
    
                background: pink;
            }
        </style>
    </head>
    <body>
        <ul>
            <li>不做</li>
            <li>不想做</li>
            <li>不做</li>
            <li>去玩</li>
            <li>想吃</li>
        </ul>
        <section>
            <div>作业</div>
            <div>前端作业</div>
            <div>html</div>
            <div>游戏</div>
            <div>粽子</div>
        </section>
        <script>
            // 通过标签名选择标签 选择所有标签名为li的标签 。类数组
            var tags=document.getElementsByTagName('li');
            var boxs=document.getElementsByTagName('div');
            // 通过标签名选择的标签，不能直接进行操作，需要选择到具体某一个进行操作
            // tags[0].style.color='red';
            for(var i=0;i<tags.length;i++){
                // 自定义属性值 选择标签.自定义属性=值
                tags[i].index=i;
                tags[i].onclick=function(){
                    // 所有的标签，删除背景。排他
                    for(var j=0;j<tags.length;j++){
                        tags[j].style.background="none";
                        // 隐藏标签
                        boxs[j].style.display="none"
                    }
                    // this代表用户当前操作的标签，事件源
                    this.style.background='limegreen';
                    // 获取刚刚自定义的属性
                    var n=this.index;
                    // display:block显示标签
                    boxs[n].style.display='block'
                }
            }
        </script>
    </body>
</html>